package l.l.w.leetcode._011ContainerWithMostWater;

/**
 * Created by llw on 2018/5/16/0016.
 */
public class _011ContainerWithMostWater {

    public int maxArea(int[] height) {
        int left = 0, right = 0;
        int i = 0, j = height.length - 1;
        int max = 0, water = 0;
        while(i < j){
            if(height[i] > height[j]){
                right = height[j];
                water = (j - i) * height[j];
                while(j > i && height[j] <= right)j--;
            }else{
                left = height[i];
                water = (j - i) * height[i];
                while(i < j && height[i] <= left)i++;
            }
            if(water > max) max = water;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] heigth = {1,2,4,3};
        int result = new _011ContainerWithMostWater().maxArea(heigth);
        System.out.println(result);
    }
}
